package com.xizhao.boot.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * SpringBoot 网络配置 跨域等
 *
 #mvc配置汇总
 #  WebMvcConfigurationSupport addResourceHandlers
 * https://blog.csdn.net/qq_44713454/article/details/111938735
 * https://www.cnblogs.com/XtsLife/p/11383451.html
 * https://www.cnblogs.com/jayinnn/p/10149776.html
 * https://blog.csdn.net/qq_46077249/article/details/111467875
 * @since 1.0
 */
@Configuration
public class ConfigWebMvc implements WebMvcConfigurer { // 或WebMvcConfigurerAdapter

//	public ConfigWebMvc() {
//		System.out.println("ConfigWebMvc");
//	}

	/**
	 * CORS 跨域支持
	 *
	 * @param registry
	 */
	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**")
//				.allowedOrigins("*")
				.allowCredentials(true)
				.allowedOriginPatterns("*")
//				.allowedHeaders("*")
				.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
				.maxAge(3600);
	}

}
